<template>
  <!-- 物流跟踪 -->
  <div>
    <van-nav-bar fixed title="物流跟踪" left-arrow class="bg-primary color-white" @click-left="back" />
    <div class="has-top ">
      <div class="info">
        <div class="product ">
          <div class="flex-v-c product-img-box">
            <div v-for="(item,index) in imgList" :key="index" class="pos-r">
              <img-box class="img-box" :img-url="item.ProductImg" />
              <span class="img-num">x{{ item.Amount }}</span>
            </div>
          </div>
          <span class="btn">{{ expressData.StateDescription }}</span>
        </div>
        <p class="flex-s-c ptb-25 hb">
          <span class="color-gray fs-28"><span v-show="expressData.ExpressName">{{ expressData.ExpressName }}：</span>{{ expressData.ExpressNumber }}</span>
          <button class="copy-btn color-gray" :data-clipboard-text="expressData.ExpressNumber" @click="copy">复制</button>
        </p>
        <!-- 快递员信息 -->
        <!-- <div class="flex-s-c pt-30">
          <headPortrait-box
            class="is-88"
            head-portrait-url=""
          />
          <div class="flex-1 ml-20">
            <p>
              <span class="job-tle">快递员</span>
              <span class="fs-32">好实用</span>
            </p>
            <p class="color-gray-light">13888888888</p>
          </div>
          <svg-icon icon-class="tel1" class="fs-60 color-primary" @goPage="" />
        </div> -->
      </div>

      <div class="detail">

        <div class="detail-item">
          <svg-icon icon-class="express-state-8" class="item-icon" />
          <p>【收货地址】{{ model.ProvinceName }}{{ model.CityName }}{{ model.AreaName }}{{ model.StreetName }}{{ model.ContactAddress }}</p>
        </div>

        <div v-for="(item,index) in expressDetail" :key="index" class="detail-item">
          <div class="item-date">
            <p class="fs-22">{{ item.date }}</p>
            <p class="fs-18 color-gray-light">{{ item.time }}</p>
          </div>
          <p class="item-icon-1" />
          <p>{{ item.NodeInfo }}</p>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import imgBox from 'components/imgBox'
import Clipboard from 'clipboard'
export default {
  name: 'ExpressDetail',
  components: { imgBox },
  props: {
    model: { // 数据对象
      type: Object,
      required: false,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {

    }
  },
  computed: {
    expressData() {
      const _obj = this.model.OrderSendModel || {}
      return _obj
    },
    expressDetail() {
      const _this = this
      let _Arr = []
      if (_this.model.OrderSendModel && _this.model.OrderSendModel.ExpressOrder) {
        _Arr = _this.model.OrderSendModel.ExpressOrder.Detail || []
        if (_Arr && _Arr.length > 0) {
          _Arr.forEach(item => {
            if (item.AddTime) {
              item.date = _this.$utils.dateFomat('mm-dd', new Date(item.AddTime))
              item.time = _this.$utils.dateFomat('HH:MM', new Date(item.AddTime))
            }
          })
        }
      }
      return _Arr
    },
    imgList() {
      const _arr = this.model.DetailList || []
      return _arr
    }
  },

  methods: {
    back() {
      this.$emit('back')
    },
    copy() {
      const _this = this
      var clipboard = new Clipboard('.copy-btn')
      clipboard.on('success', e => {
        const instance = _this.$toast('复制成功')
        setTimeout(() => {
          instance.close()
        }, 2000)

        // 释放内存
        clipboard.destroy()
      })

      clipboard.on('error', e => {
        // 不支持复制
        const instance = _this.$toast('该浏览器不支持自动复制')
        setTimeout(() => {
          instance.close()
        }, 2000)

        // 释放内存
        clipboard.destroy()
      })
    }
  }

}
</script>
<style lang="scss" scoped>
.color-white {
  /deep/.van-icon {
    color: #fff;
  }
  /deep/.van-nav-bar__title {
    color: #fff;
  }
  &:after{
    border-bottom:none;
  }
}
.info{
  background: $colorF;
  margin: 20px;
  border-radius: 4px;
  padding: 25px 20px;
  overflow: hidden;
  .product{
    position: relative;
    padding-right: 160px;
    .product-img-box{
      width: 100%;
      overflow-x: scroll;
      .img-box{
        width: 88px;
        height: 88px;
        border-radius: 8px;
        display: inline-block;
        overflow: hidden;
        flex-shrink: 0;
        flex-grow: 0;
        margin-right: 20px;
        &:last-child{
          margin-right: 0px;
        }
      }
      .img-num{
        position: absolute;
        display: inline-block;
        min-width: 40px;
        line-height: 24px;
        text-align: center;
        font-size: 18px;
        color:$colorF;
        bottom: 10px;
        right: 20px;
        background: #040000;
        border-radius: 8px 0 8px 0;
      }
    }
    .btn{
      position: absolute;
      width: 160px;
      height: 88px;
      text-align: center;
      right: 0;
      top: 0;
      font-size: 32px;
      line-height: 88px;
      @include color-primary;
      border-radius: 8px;
      box-shadow: 0px 0px 10px rgba(4, 0, 0, 0.09);
    }
  }
  .copy-btn{
    font-size: 20px;
    line-height: 36px;
    border-radius: 18px;
    padding: 0 15px;
    background: #F0F0F0;
  }
  .job-tle{
    margin-right: 17px;
    color:$colorF;
    @include bg-primary;
    display: inline-block;
    line-height: 1.5;
    border-radius: 8px;
    padding: 0 8px;
  }
}
.detail{
  background: $colorF;
  margin: 20px;
  border-radius: 4px;
  padding: 30px 20px;
  overflow: hidden;
  .detail-item{
    position: relative;
    padding-bottom: 50px;
    padding-left: 34px;
    margin-left: 120px;
    color: $color9;
    border-left: 1px solid #f0f0f0;
    &:first-child{
      color:$color3;
      border-left: 1px dashed #f0f0f0;
      .item-icon,.item-icon-1{
        @include color-primary;
      }
    }
    &:nth-child(2){
      color:$color3;
      .item-icon,.item-icon-1{
        @include color-primary;
      }
    }
    &:last-child{
      border-left: none;
    }
    .item-date{
      position: absolute;
      top: 0;
      left: -120px;
      width: 88px;
      text-align: right;
    }
    .item-icon{
      position: absolute;
      top: 0;
      left: -24px;
      font-size: 48px;
      background: $colorF;
    }
    .item-icon-1{
      width: 24px;
      height: 24px;
      position: absolute;
      top: 0;
      left: -12px;
      background: $colorF;
      &:after{
        position: absolute;
        content: '';
        width: 12px;
        height: 12px;
        left: 6px;
        top: 6px;
        border-radius: 100%;
        background: currentColor;
      }
    }
  }
}
</style>
